using System.Drawing;
using System.Windows.Forms;
using Tiwo.Design.Renderers;

namespace Tiwo.Design.Trackers
{
    class DragRendererMouseTracker : IMouseTracker
    {
        public SchemeRenderSite Site { get; set; }
        public Cursor Cursor { get { return Cursors.SizeAll; } }

        public RectangularRenderer Renderer { get; set; }

        private PointF DragStartPoint { get; set; }
        private PointF RendererStartPoint { get; set; }

        public DragRendererMouseTracker(RectangularRenderer renderer)
        {
            Renderer = renderer;
        }

        public void MouseDown(Point location)
        {
            DragStartPoint = location;
            RendererStartPoint = Renderer.Location;
        }

        public void MouseMove(Point location)
        {
            if (DragStartPoint.IsEmpty) return;

            var startPoint = RendererStartPoint;
            startPoint.X += location.X - DragStartPoint.X;
            startPoint.Y += location.Y - DragStartPoint.Y;

            Renderer.Location = startPoint;
            Site.Invalidate();
        }

        public void MouseUp(Point location) { }

        public void DrawTo(Graphics graphics, IRenderingCache rendering)
        {
            graphics.DrawRectangle(Pens.LightBlue, Renderer.Location.X, Renderer.Location.Y, Renderer.Size.Width, Renderer.Size.Height);
        }
    }
}